package com.vlada.studzad.pages;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.vlada.studzad.data.MockDataEmployerSource;
import com.vlada.studzad.model.Employer;
import com.vlada.studzad.model.Privilege;
import com.vlada.studzad.model.User;

public class CreateEmployerProfile {
	
	@ApplicationState
	@Property
	private User user;
	private boolean userExists;	
	
	Object onActivate() {
		if (!userExists)return Index.class;
		else if(user.getPrivilege()==Privilege.ADMINISTRATOR){
			return null;
		}
		return Index.class;
	}
	
	@ApplicationState
	private MockDataEmployerSource employers;
	
	@Persist
	private Employer employer;

	public void setEmployer(Employer employer) {
		this.employer = employer;
	}

	public Employer getEmployer() {
		return employer;
	}
	
    Object onSuccess()
    {
        employers.addEmployer(employer);

        return null;
    }
	
}
